import * as actionTypes from "./action-types";

// action types
//初始数据
const initialState = {
    username:  '',
    userId:  '',
    token: '',
    avatar: '',
}

const user = (state = initialState, action) => {
    switch (action.type) {
        case actionTypes.LOGIN:
            return Object.assign({}, state, {
                token:action.token
            })
        case actionTypes.LOGOUT:
            return {
                ...state,
                username: '',
                token: '',
                avatar: '',
                userId: ''
            }
        case actionTypes.UPDATE_INFO:
            return Object.assign({}, state, {
                ...action.payload
            })
        case actionTypes.SET_AVATAR:
            return Object.assign({}, state, {
                avatar: action.avatar
            })
        case actionTypes.SET_USERNAME:
            return Object.assign({}, state, {
                username:action.username
            })
        default:
            return state
    }
}


export default user